<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8" />
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>职位详情</title>
	<link rel="stylesheet" href="css/mui.min.css" />
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">
	<!-- build:css css/app.css -->
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/common.css">
	<!-- endbuild -->
	<style type="text/css">
		.mui-content {
			background: #FFFFFF;
		}

		.social-share {
			display: none;
			position: fixed;
			z-index: 11;
			bottom: -60px;
			width: 100%;
			padding: 8px;
			transition: all .2s ease-in;
			justify-content: space-around;
			background: #FFFFFF;
		}

		.social-share .social-share-icon {
			width: 45px;
			height: 45px;
			font-size: 26px;
			line-height: 42px;
		}

		.social-share .icon-wechat .wechat-qrcode {
			top: -170px;
			left: -53px;
			width: 150px;
			height: 150px;
		}

		.mui-backdrop {
			z-index: 10;
			background:rgba(0,0,0,.7);
			/* background:rgba(0,0,0,.7) url('./img/guide1.png') no-repeat top right; */
			/* background-size: 60%; */
			/* background-position: 86% 30px; */
		}

		.introduction {
			padding: 10px 0;
			border-top: 5px solid #efeff4;
		}

		.introduction.position {
			padding-top: 0;
		}

		.introduction .title {
			margin-bottom: 6px;
			font-size: 18px;
		}

		.introduction .time {
			color: #d3d3d3;
			font-size: 14px;
		}

		.introduction .money {
			margin-bottom: 4px;
			color: #ff0b00;
			font-size: 18px;
		}

		.recruit-info li {
			margin-bottom: 4px;
		}

		.recruit-info li span {
			margin-right: 6px;
			color: #999999;
			font-size: 14px;
		}

		.recruit-info li img {
			vertical-align: -1px;
		}

		.recruit-info li.welfare,
		.recruit-info li.welfare span {
			margin-right: 0;
			color: #ff7552;
			font-size: 14px;
		}

		.recruit-info li.welfare span:after {
			content: ' | ';
			vertical-align: 1px;
		}

		.recruit-info li.welfare span:last-child::after {
			content: none;
		}

		.position-title {
			margin-bottom: 8px;
			text-indent: 4%;
			font-size: 16px;
			padding: 6px 0;
			border-bottom: 1px solid #eeeeee;
		}

		.position-desc {
			font-size: 14px;
			color: #777777;
		}

		.position-desc p.title {
			color: #777777;
			font-size: 16px;
		}

		.footer-bar {
			position: fixed;
			left: 0;
			bottom: 0;
			z-index: 5;
			width: 100%;
			border-top: 5px solid #efeff4;
		}

		.footer-bar .contacts {
			height: 80px;
			justify-content: center;
			text-align: center;
			background: #FFFFFF;
			border-bottom: 5px solid #efeff4;
		}

		.footer-bar .contacts img {
			margin-left: 15px;
			width: 30px;
			height: 30px;
			cursor: pointer;
		}

		.footer-bar .functions {
			height: 50px;
			background: #FFFFFF;
		}

		.footer-bar .functions .function-list {
			flex: 1;
			height: 50px;
			line-height: 18px;
			text-align: center;
		}

		.footer-bar .functions .mui-text-center {
			flex: 1;
			transition: all .1s ease;
			-webkit-transition: all .1s ease;
			-moz-transition: all .1s ease;
			-ms-transition: all .1s ease;
		}

		.footer-bar .functions .function-list span {
			display: block;
			font-size: 12px;
		}

		.footer-bar .functions .function-list button {
			width: 100%;
			height: 50px;
			margin: 0;
			font-size: 17px;
			border-radius: 0;
		}

		.footer-bar .functions .function-list .mui-text-center:first-child img {
			width: 17px;
			height: 17px;
		}

		.footer-bar .functions .function-list .mui-text-center:nth-child(2) img {
			width: 19px;
			height: 18px;
		}
	</style>
</head>

<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">职位详情</h1>
	</header>
	<div class="mui-content"></div>
	<div class="social-share"></div>
	<div class="footer-bar">
		<div class="contacts flex-row-center">
			<div style="margin-left: 45px;">
				<div id="name" style="height: 20px;"></div>
				<span id="phone" class="red"></span>
			</div>
			<a href="javascript:;" id="callPhone">
				<img src="img/phone.png" />
			</a>
		</div>
		<div class="functions flex-row-center">
			<div class="function-list flex-row-center">
				<div id="share" class="mui-text-center">
					<img src="img/icon_bs_fenxiang.png" />
					<span>分享</span>
				</div>
				<div id="live" class="mui-text-center">
					<img src="img/icon_zwxq_sc.png" />
					<span>收藏</span>
				</div>
			</div>
			<div class="function-list">
				<button id="delivery" class="button button-blue" disabled>投递简历</button>
			</div>
		</div>
	</div>
	<script src="js/mui.min.js"></script>
	<script src="js/zepto.min.js"></script>
	<script src="js/template-web.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>
	<!-- build:js js/app.js -->
	<script src="js/api.js"></script>
	<script src="js/tools.js"></script>
	<!-- endbuild -->
	<script src="js/utils.js"></script>
	<script src="js/jweixin-1.0.0.js"></script>
	<script type="text/javascript">
		$(function () {
			// 获取职位id
			var href = window.location.href;
			var number = null;
			if (href.indexOf('?rid') != -1) {
				href = href.split('rid=')[1];
				if (href.indexOf('&') != -1) {
					rid = href.split('&')[0]
				} else {
					rid = href
				}
			} else {
				mui.toast('获取职位失败!')
			}
			$('.mui-content').css({
				'height': $(window).height() - 135,
				'overflowY': 'auto'
			})
			function init(res) {
				document.title = '同道招聘-' + res.positionName;
				$('#name').text(res['contacts']);
				$('#phone').text(this.phoneFormat(res['contactsPhone']));
				$('.mui-content').prepend(template('job', res))
				number = res['contactsPhone'];
			}
			// 加载职位信息
			mui.ajax(config.HOME_API + 'app/recruitment', {
				data: {
					recruitmentId: rid
				},
				dataType: 'json',
				type: 'post',
				timeout: 10000,
				success: function (res) {
					if (res.code == 2) {
						init(res.data.recruitment)
					} else {
						mui.toast(res.msg)
					}
				}
			});
			// 微信分享
			$.ajax({
				// url: 'https://king.tongdao.ink/wechatParam?url=' + encodeURIComponent(window.location.href),
				url: 'http://192.168.0.192:8090/app/wechatParam?url=' + encodeURIComponent(window.location.href),
				type: "get",
				datatype: "json",
				async: true,
				timeout: 30000,
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					console.log('进入到error')
					console.log('status:' + XMLHttpRequest.status);
					console.log('readyState:' + XMLHttpRequest.readyState);
					console.log('textStatus:' + textStatus);
					////alert(textStatus);
					// weixinSign()
				},
				success: function (json) {
					if (json.code == '2') {
						console.log(json)
						wx.config({
							debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来
							appId: json.data.appid,
							nonceStr: json.data.nonceStr,
							timestamp: json.data.timestamp,
							signature: json.data.signature,
							jsApiList: [
								"onMenuShareTimeline",//分享朋友圈接口
								"onMenuShareAppMessage",//分享给朋友接口
								"checkJsApi"
							] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
						});

						wx.ready(function () {
							console.log('分享前')
							wx.onMenuShareTimeline({
								title: document.title,
								desc: $('.position-desc').text(),
								link: location.href,
								imgUrl: window.localStorage.getItem("h5_comp_logo"),
								trigger: function (res) {
									// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
									// alert('用户点击发送给朋友');
								},
								success: function (res) {
									console.log('已分享');
								},
								cancel: function (res) {
									console.log('已取消');
								},
								fail: function (res) {
									console.log(JSON.stringify(res));
								}
							});

							wx.onMenuShareAppMessage({
								title: document.title,
								desc: $('.position-desc').text(),
								link: location.href,
								imgUrl: window.localStorage.getItem("h5_comp_logo"),
								trigger: function (res) {
									// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
									// alert('用户点击发送给朋友');
								},
								success: function (res) {
									console.log('已分享');
								},
								cancel: function (res) {
									console.log('已取消');
								},
								fail: function (res) {
									console.log(JSON.stringify(res));
								}
							});
							wx.error(function (res) {
								alert(res.errMsg);
							});
						});
					} else {
						//  alert(json.msg)
					}
				},
				complete: function (XMLHttpRequest, status) {
					if (status == 'timeout') {
						alert("网络异常!");
					}
				}
			});
			// 打电话
			$("#callPhone").on('tap', function () {
				if (!isLogin()) {
					mui.toast('请先登录!');
					return false
				}
				$.ajax({
					url: config.ME_API + 'h5/h5GetOneDeliveryResume',
					type: 'post',
					data: {
						resumeId: getRid(),
						recruitmentId: rid
					},
					success: function (res) {
						if (res.code != 2) {
							mui.confirm('拨打电话需要投递一份简历哦!')
						}
					}
				})
			})
			// 查看是否收藏
			$.ajax({
				url: config.ME_API + 'h5/h5GetOneCollectionPosition',
				type: 'post',
				data: {
					resumeId: getRid(),
					recruitmentId: rid
				},
				success: function (res) {
					if (res.code == 2) {
						$('#live').attr('status', true).find('span').text('已收藏');
						$('#live').css('opacity', 1).find('img').prop('src', 'img/icon_zwxq_sc_active.png')
					} else {
						$('#live').attr('status', false).find('span').text('收藏');
						$('#live').css('opacity', 1).find('img').prop('src', 'img/icon_zwxq_sc.png')
					}
				}
			})
			// 收藏
			$('#live').on('tap', throttle(function () {
				if (!isLogin()) {
					mui.toast('请先登录!');
					return false
				}
				mui.ajax(config.ME_API + 'h5/h5GetResume', {
					data: {
						h5UserId: getUserId()
					},
					dataType: 'json',
					type: 'post',
					timeout: 10000,
					success: function (res) {
						if (res.code == 1) {
							mui.confirm(' 请先创建简历!', '您的简历不完整!', function (res) {
								if (res.index) {
									setTimeout(function () {
										mui.openWindow('my-create-resume.html')
									}, 500)
								}
							})
							return false
						}
						if (res.code == 2) {
							res = res.data.appTdResume;
							var arr = [];
							var status = 0;
							window.localStorage.setItem('rid', res.rid);
							config.resume.forEach(element => {
								if (res[element] == null || res[element] == '') {
									arr.push(element)
								}
							});
							if (arr.length > 6) {
								mui.confirm('是否前去补充完整简历', '您的简历信息不完整!', function (res) {
									if (res.index) {
										setTimeout(function () {
											mui.openWindow("my-edit-resume.html")
										}, 500)
									}
								})
								return false
							}
							if ($('#live').attr('status') == 'false') {
								$.ajax({
									url: config.ME_API + 'h5/h5SaveCollectionPosition',
									type: 'post',
									data: {
										resumeId: getRid(),
										recruitmentId: rid
									},
									success: function (res) {
										console.log(res)
										if (res.code == 2) {
											$('#live').attr('status', true).find('span').text('已收藏');
											$('#live').find('img').prop('src', 'img/icon_zwxq_sc_active.png')
										} else {
											mui.toast(res.msg)
										}
									}
								})
							} else {
								$.ajax({
									url: config.ME_API + 'h5/h5DelCollectionPosition',
									type: 'post',
									data: {
										resumeId: getRid(),
										recruitmentId: rid
									},
									success: function (res) {
										console.log(res)
										if (res.code == 2) {
											$('#live').attr('status', false).find('span').text('收藏');
											$('#live').find('img').prop('src', 'img/icon_zwxq_sc.png')
										} else {
											mui.toast(res.msg)
										}
									}
								})
							}
						} else {
							mui.toast('服务器繁忙，请稍后再试!')
						}
					},
					error: function (xhr, type, errorThrown) {
						mui.toast('请稍后再试!')
					}
				});
			}, 3000));
			// 查看投递状态
			$.ajax({
				url: config.ME_API + 'h5/h5GetOneDeliveryResume',
				type: 'post',
				data: {
					resumeId: getRid(),
					recruitmentId: rid
				},
				success: function (res) {
					if (res.code == 2) {
						var date = res.data.createTime;
						var now = new Date().getTime();
						$('#callPhone').prop('href', 'tel:' + number);
						$('#delivery').text('已投递').prop('disabled', true);
						if ((now - date) / (1000 * 3600 * 24) > 7) {
							$('#delivery').text('投递简历').prop('disabled', false);
						}
					} else {
						$('#delivery').text('投递简历').prop('disabled', false);
					}
				}
			})
			// 投递简历
			$("#delivery").on('tap', throttle(function () {
				if (isLogin()) {
					mui.ajax(config.ME_API + 'h5/h5GetResume', {
						data: {
							h5UserId: getUserId()
						},
						dataType: 'json',
						type: 'post',
						timeout: 10000,
						success: function (res) {
							if (res.code == 1) {
								mui.confirm(' 请先创建简历!', '您的简历不完整!', function (res) {
									if (res.index) {
										setTimeout(function () {
											mui.openWindow('my-create-resume.html')
										}, 500)
									}
								})
								return false
							}
							if (res.code == 2) {
								res = res.data.appTdResume;
								var arr = [];
								var status = 0;
								window.localStorage.setItem('rid', res.rid);
								config.resume.forEach(element => {
									if (res[element] == null || res[element] == '') {
										arr.push(element)
									}
								});
								if (arr.length > 6) {
									mui.confirm('是否前去补充完整简历', '您的简历信息不完整!', function (res) {
										if (res.index) {
											setTimeout(function () {
												mui.openWindow("my-edit-resume.html")
											}, 500)
										}
									})
									return false
								}
								mui.confirm('是否投递该职位', document.title, function (res) {
									if (res.index) {
										$.ajax({
											url: config.ME_API + 'h5/h5DeliveryResume',
											type: 'post',
											data: {
												resumeId: getRid(),
												recruitmentId: rid
											},
											success: function (res) {
												if (res.code == 2) {
													mui.toast('投递成功!');
													$('#callPhone').prop('href', 'tel:' + number);
													$('#delivery').text('已投递').prop('disabled', true);
												} else {
													mui.toast(res.msg)
												}
											}
										})
									}
								})
							} else {
								mui.toast('服务器繁忙，请稍后再试!')
							}
						},
						error: function (xhr, type, errorThrown) {
							mui.toast('请稍后再试!')
						}
					});
				} else {
					mui.confirm('请先登录!', '', '', function (res) {
						if (res.index) {
							setTimeout(function () {
								mui.openWindow('login.html')
							}, 1000)
						}
					})
					return false
				}
			}, 3000));
			// 如果没有历史记录返回到首页
			$('.mui-action-back').on('tap', function () {
				var href = window.location.href;
				if (href.indexOf('&comp_id') != -1) {
					href = href.split('&comp_id=')[1];
					if (window.history.length == 1) {
						mui.openWindow('./index.html?comp_id=' + href)
					}
				} else {
					mui.openWindow('./index.html')
				}
			})
		})
		// 分享
		var $config = {
			source: '同道招聘', // 来源（QQ空间会用到）, 默认读取head标签：<meta name="site" content="http://overtrue" />
			title: document.title,
			description: '同道招聘-' + document.title, // 描述, 默认读取head标签：<meta name="description" content="PHP弱类型的实现原理分析" />
			image: 'http://sysmanager.oss-cn-beijing.aliyuncs.com/header/1559495335prefix4285650147954994599_icon_touxiang.png', // 图片, 默认取网页中第一个img标签
			sites: ['weibo', 'wechat', 'qzone', 'qq'], // 启用的站点
			wechatQrcodeTitle: '微信扫一扫分享', // 微信二维码提示文字
			wechatQrcodeHelper: ''
		};
		socialShare('.social-share', $config);
		$('#share').on('tap', function () {
			var mask = mui.createMask(function () {
				this.close();
				$('.social-share').hide()
			});
			mask.show();
			$('.social-share').css({
				'display': 'flex',
				'bottom': '51px'
			})
		})
	</script>
	<script id="job" type="text/html">
		<div class="introduction">
			<div class="content">
				<div class="flex-row">
					<div id="title" class="title"><%=positionName%></div>
					<div class="time"><%=$imports.miniFormat(updateTime)%></div>
				</div>
				<div class="money"><%=$imports.config.salaryRange[payMoney]%></div>
				<ul class="recruit-info">
					<li>
						<img width="15px" height="14px" src=img/age.png alt="">
						<span><%=ageRequire%></span>
						<img width="11px" height="15px" src=img/zhaopin.png alt="">
						<span>招<%=recruitmentHow%>人</span>
						<img width="16px" height="15px" src=img/xueli.png alt="">
						<span><%=$imports.config.edu[educationRequire]%></span>
					</li>
					<li>
						<img width="13px" height="17px" src=img/address.png alt="">
						<span><%=jobAddress%></span>
					</li>
					<li class="welfare">
						<img width="14px" height="14px" src=img/welfare.png alt=""> 福利：
						<% var welfareTreatment =  welfareTreatment.split(',')%>
						<%for (var j = 0; j < welfareTreatment.length; j ++) {%>
							<% if (welfareTreatment[j] != '') { %>
								<span><%=$imports.config.welfare[welfareTreatment[j]]%></span>
							<% } else {%>
								<span>暂无福利</span>
							<%} %>
						<%}%>
					</li>
				</ul>
			</div>
		</div>
		<div class="introduction position">
			<div class="position-title">职位详情</div>
			<div class="content">
				<div class="position-desc">
					<% if(jobRequire) {%>
						<p class="title">任职要求：</p>
						<p><%=jobRequire%></p>
					<%}%>
					<p class="title">职位描述：</p>
					<p style="white-space: pre-wrap;"><%=positionDescH5.replace(/<br>/g,'\n')%></p>
				</div>
			</div>
		</div>
	</script>
</body>

</html>